######################################################Standardizing variables
install.packages("readr")

library(readr)
clean_dating2 <- read.csv("clean_dating2.csv")
View(clean_dating2)

install.packages("ggplot2")
library(ggplot2)
######################################################
######################################################Attractiveness Score
clean_dating2$attractiveness_score <- scale(clean_dating2$attractiveness_score)
summary(clean_dating2$attractiveness_score)
sd(clean_dating2$attractiveness_score, na.rm = TRUE)

#First is the mean attractiveness score, by the treatment
data.summary1 <- tapply(clean_dating2$attractiveness_score, clean_dating2$treatment, mean)
#Then, we need the n (to find standard error in a bit)
data.summary2 <- tapply(clean_dating2$attractiveness_score, clean_dating2$treatment, length)
#Next is the standard deviation, by the treatment
data.summary3 <- tapply(clean_dating2$attractiveness_score, clean_dating2$treatment, sd)

###Making this so that I can merge all the variables in a hot sec
data.summary4 <- c(1, 1, 1)

#Now that we have our values, we will put them into a dataset.
#Note: we have to manually create the treatment columns so we can put the above values in.
data.summary <- data.frame("treatment" = 0:2)
#Stick in the other variables
data.summary$mean <- data.summary1
data.summary$n <- data.summary2
data.summary$sd <- data.summary3
data.summary$number <- data.summary4
#Now, the magic of getting the standard error
data.summary$se <- data.summary$sd/sqrt(data.summary$n)

######################################################
######################################################Respond to a message
clean_dating2$respond_message <- scale(clean_dating2$respond_message)
summary(clean_dating2$respond_message)
sd(clean_dating2$respond_message, na.rm = TRUE)

#First is the mean attractiveness score, by the treatment
data.summary1 <- tapply(clean_dating2$respond_message, clean_dating2$treatment, mean)
#Then, we need the n (to find standard error in a bit)
data.summary2 <- tapply(clean_dating2$respond_message, clean_dating2$treatment, length)
#Next is the standard deviation, by the treatment
data.summary3 <- tapply(clean_dating2$respond_message, clean_dating2$treatment, sd)

###Making this so that I can merge all the variables in a hot sec
data.summary4 <- c(2, 2, 2)

#Now that we have our values, we will put them into a dataset.
#Note: we have to manually create the treatment columns so we can put the above values in.
data.summaryMESSAGE <- data.frame("treatment" = 0:2)
#Stick in the other variables
data.summaryMESSAGE$mean <- data.summary1
data.summaryMESSAGE$n <- data.summary2
data.summaryMESSAGE$sd <- data.summary3
data.summaryMESSAGE$number <- data.summary4
#Now, the magic of getting the standard error
data.summaryMESSAGE$se <- data.summaryMESSAGE$sd/sqrt(data.summaryMESSAGE$n)

######################################################
######################################################Go on a Date
clean_dating2$go_date <- scale(clean_dating2$go_date)
summary(clean_dating2$go_date)
sd(clean_dating2$go_date, na.rm = TRUE)

#First is the mean attractiveness score, by the treatment
data.summary1 <- tapply(clean_dating2$go_date, clean_dating2$treatment, mean)
#Then, we need the n (to find standard error in a bit)
data.summary2 <- tapply(clean_dating2$go_date, clean_dating2$treatment, length)
#Next is the standard deviation, by the treatment
data.summary3 <- tapply(clean_dating2$go_date, clean_dating2$treatment, sd)

###Making this so that I can merge all the variables in a hot sec
data.summary4 <- c(3, 3, 3)

#Now that we have our values, we will put them into a dataset.
#Note: we have to manually create the treatment columns so we can put the above values in.
data.summaryDATE <- data.frame("treatment" = 0:2)
#Stick in the other variables
data.summaryDATE$mean <- data.summary1
data.summaryDATE$n <- data.summary2
data.summaryDATE$sd <- data.summary3
data.summaryDATE$number <- data.summary4
#Now, the magic of getting the standard error
data.summaryDATE$se <- data.summaryDATE$sd/sqrt(data.summaryDATE$n)

######################################################
######################################################Enter Relationship
clean_dating2$relationship <- scale(clean_dating2$relationship)
summary(clean_dating2$relationship)
sd(clean_dating2$relationship, na.rm = TRUE)

#First is the mean attractiveness score, by the treatment
data.summary1 <- tapply(clean_dating2$relationship, clean_dating2$treatment, mean)
#Then, we need the n (to find standard error in a bit)
data.summary2 <- tapply(clean_dating2$relationship, clean_dating2$treatment, length)
#Next is the standard deviation, by the treatment
data.summary3 <- tapply(clean_dating2$relationship, clean_dating2$treatment, sd)

###Making this so that I can merge all the variables in a hot sec
data.summary4 <- c(4, 4, 4)

#Now that we have our values, we will put them into a dataset.
#Note: we have to manually create the treatment columns so we can put the above values in.
data.summaryREL <- data.frame("treatment" = 0:2)
#Stick in the other variables
data.summaryREL$mean <- data.summary1
data.summaryREL$n <- data.summary2
data.summaryREL$sd <- data.summary3
data.summaryREL$number <- data.summary4
#Now, the magic of getting the standard error
data.summaryREL$se <- data.summaryREL$sd/sqrt(data.summaryREL$n)

######################################################
######################################################Set up with a friend
clean_dating2$set_up_friend <- scale(clean_dating2$set_up_friend)
summary(clean_dating2$set_up_friend)
sd(clean_dating2$set_up_friend, na.rm = TRUE)

#First is the mean attractiveness score, by the treatment
data.summary1 <- tapply(clean_dating2$set_up_friend, clean_dating2$treatment, mean)
#Then, we need the n (to find standard error in a bit)
data.summary2 <- tapply(clean_dating2$set_up_friend, clean_dating2$treatment, length)
#Next is the standard deviation, by the treatment
data.summary3 <- tapply(clean_dating2$set_up_friend, clean_dating2$treatment, sd)

###Making this so that I can merge all the variables in a hot sec
data.summary4 <- c(5, 5, 5)

#Now that we have our values, we will put them into a dataset.
#Note: we have to manually create the treatment columns so we can put the above values in.
data.summarySET <- data.frame("treatment" = 0:2)
#Stick in the other variables
data.summarySET$mean <- data.summary1
data.summarySET$n <- data.summary2
data.summarySET$sd <- data.summary3
data.summarySET$number <- data.summary4
#Now, the magic of getting the standard error
data.summarySET$se <- data.summarySET$sd/sqrt(data.summarySET$n)

########################################################################
########################################################################
######################################################################## Mergy Mergy chicken dinner

rom <- merge(data.summary, data.summaryMESSAGE, by=c("number", "n", "sd", "se", "treatment", "mean"), all=TRUE)
rom2 <- merge(rom, data.summaryDATE, by=c("number", "n", "sd", "se", "treatment", "mean"), all=TRUE)
rom3 <- merge(rom2, data.summaryREL, by=c("number", "n", "sd", "se", "treatment", "mean"), all=TRUE)
rom4 <- merge(rom3, data.summarySET, by=c("number", "n", "sd", "se", "treatment", "mean"), all=TRUE)

#Let's create some color
rom4$color <- NA
rom4$color[rom4$treatment==0] <- "darkgrey"
rom4$color[rom4$treatment==1] <- "maroon"
rom4$color[rom4$treatment==2] <- "steelblue"

#For whatever reason, the line colors were getting crazy. So, here's my attempt to fix it
#(manually giving more color)
#rom4$color2 <- NA
#rom4$color2[rom4$number<=2] <- "grey"
#rom4$color2[rom4$sd=='1.0292806'] <- "maroon"
#rom4$color2[rom4$number==3] <- "maroon"
#rom4$color2[rom4$number>=4] <- "steelblue"
rom4$color3 <- c("darkgrey", "darkgrey", "darkgrey", "darkgrey", "maroon", "maroon", "maroon", "maroon", "maroon", "steelblue",
                 "steelblue", "steelblue", "steelblue", "steelblue", "steelblue")
##########################
########################## Let's Graph, Paw Patrol!
bb <- ggplot(data = rom4, aes(x=number, y=mean, group=treatment)) +
  xlim(0.8,5.2) +
  geom_point(color = rom4$color, size = 5, alpha =0.5) +
  geom_line(color = rom4$color3, size= 6, alpha=0.6) +
  geom_errorbar(aes(ymin=rom4$mean-(1.96*rom4$se), ymax=rom4$mean+(1.96*rom4$se)), width=0, 
                color=rom4$color, size = 2, alpha = 0.8) +
  labs(title="", x="", y = "Average Score, standardized") +
  theme_classic() +
  annotate("text", x = 1, y = -0.32, label = "Attractiveness", size = 9, color = "#494949") +
  annotate("text", x = 1, y = -0.36, label = "Score", size = 9, color = "#494949") +
  annotate("text", x = 2, y = -0.32, label = "Respond to a", size = 9, color = "#494949") +
  annotate("text", x = 2, y = -0.36, label = "Message", size = 9, color = "#494949") +
  annotate("text", x = 3, y = -0.32, label = "Go on a", size = 9, color = "#494949") +
  annotate("text", x = 3, y = -0.36, label = "Date", size = 9, color = "#494949") +
  annotate("text", x = 4, y = -0.32, label = "Enter into a", size = 9, color = "#494949") +
  annotate("text", x = 4, y = -0.36, label = "Relationship", size = 9, color = "#494949") +
  annotate("text", x = 5, y = -0.32, label = "Set Up With a", size = 9, color = "#494949") +
  annotate("text", x = 5, y = -0.36, label = "Friend", size = 9, color = "#494949") +
  scale_x_discrete() +
  theme(text = element_text(size=40)) +
  theme(axis.title.y = element_text(margin = margin(t = 0, r = 20, b = 0, l = 0)))

print(bb) # Figure A9

########################## Let's Graph, Paw Patrol!
##################################################################################################
##################################################################################################
##################################################################################################
##################################################################################################
##################################################################################################
##################################################################################################in-n-out party

######################################################
######################################################Attractiveness Score
clean_dating2$attractiveness_score <- scale(clean_dating2$attractiveness_score)
summary(clean_dating2$attractiveness_score)
sd(clean_dating2$attractiveness_score, na.rm = TRUE)

#First is the mean attractiveness score, by the treatment
data.summary1 <- tapply(clean_dating2$attractiveness_score, clean_dating2$same_party, mean)
#Then, we need the n (to find standard error in a bit)
data.summary2 <- tapply(clean_dating2$attractiveness_score, clean_dating2$same_party, length)
#Next is the standard deviation, by the treatment
data.summary3 <- tapply(clean_dating2$attractiveness_score, clean_dating2$same_party, sd)

###Making this so that I can merge all the variables in a hot sec
data.summary4 <- c(1, 1)

#Now that we have our values, we will put them into a dataset.
#Note: we have to manually create the treatment columns so we can put the above values in.
data.summary <- data.frame("samep" = 0:1)
#Stick in the other variables
data.summary$mean <- data.summary1
data.summary$n <- data.summary2
data.summary$sd <- data.summary3
data.summary$number <- data.summary4
#Now, the magic of getting the standard error
data.summary$se <- data.summary$sd/sqrt(data.summary$n)

######################################################
######################################################Respond to a message
clean_dating2$respond_message <- scale(clean_dating2$respond_message)
summary(clean_dating2$respond_message)
sd(clean_dating2$respond_message, na.rm = TRUE)

#First is the mean attractiveness score, by the treatment
data.summary1 <- tapply(clean_dating2$respond_message, clean_dating2$same_party, mean)
#Then, we need the n (to find standard error in a bit)
data.summary2 <- tapply(clean_dating2$respond_message, clean_dating2$same_party, length)
#Next is the standard deviation, by the treatment
data.summary3 <- tapply(clean_dating2$respond_message, clean_dating2$same_party, sd)

###Making this so that I can merge all the variables in a hot sec
data.summary4 <- c(2, 2)

#Now that we have our values, we will put them into a dataset.
#Note: we have to manually create the treatment columns so we can put the above values in.
data.summaryMESSAGE <- data.frame("samep" = 0:1)
#Stick in the other variables
data.summaryMESSAGE$mean <- data.summary1
data.summaryMESSAGE$n <- data.summary2
data.summaryMESSAGE$sd <- data.summary3
data.summaryMESSAGE$number <- data.summary4
#Now, the magic of getting the standard error
data.summaryMESSAGE$se <- data.summaryMESSAGE$sd/sqrt(data.summaryMESSAGE$n)

######################################################
######################################################Go on a Date
clean_dating2$go_date <- scale(clean_dating2$go_date)
summary(clean_dating2$go_date)
sd(clean_dating2$go_date, na.rm = TRUE)

#First is the mean attractiveness score, by the treatment
data.summary1 <- tapply(clean_dating2$go_date, clean_dating2$same_party, mean)
#Then, we need the n (to find standard error in a bit)
data.summary2 <- tapply(clean_dating2$go_date, clean_dating2$same_party, length)
#Next is the standard deviation, by the treatment
data.summary3 <- tapply(clean_dating2$go_date, clean_dating2$same_party, sd)

###Making this so that I can merge all the variables in a hot sec
data.summary4 <- c(3, 3)

#Now that we have our values, we will put them into a dataset.
#Note: we have to manually create the treatment columns so we can put the above values in.
data.summaryDATE <- data.frame("samep" = 0:1)
#Stick in the other variables
data.summaryDATE$mean <- data.summary1
data.summaryDATE$n <- data.summary2
data.summaryDATE$sd <- data.summary3
data.summaryDATE$number <- data.summary4
#Now, the magic of getting the standard error
data.summaryDATE$se <- data.summaryDATE$sd/sqrt(data.summaryDATE$n)

######################################################
######################################################Enter Relationship
clean_dating2$relationship <- scale(clean_dating2$relationship)
summary(clean_dating2$relationship)
sd(clean_dating2$relationship, na.rm = TRUE)

#First is the mean attractiveness score, by the treatment
data.summary1 <- tapply(clean_dating2$relationship, clean_dating2$same_party, mean)
#Then, we need the n (to find standard error in a bit)
data.summary2 <- tapply(clean_dating2$relationship, clean_dating2$same_party, length)
#Next is the standard deviation, by the treatment
data.summary3 <- tapply(clean_dating2$relationship, clean_dating2$same_party, sd)

###Making this so that I can merge all the variables in a hot sec
data.summary4 <- c(4, 4)

#Now that we have our values, we will put them into a dataset.
#Note: we have to manually create the treatment columns so we can put the above values in.
data.summaryREL <- data.frame("samep" = 0:1)
#Stick in the other variables
data.summaryREL$mean <- data.summary1
data.summaryREL$n <- data.summary2
data.summaryREL$sd <- data.summary3
data.summaryREL$number <- data.summary4
#Now, the magic of getting the standard error
data.summaryREL$se <- data.summaryREL$sd/sqrt(data.summaryREL$n)

######################################################
######################################################Set up with a friend
clean_dating2$set_up_friend <- scale(clean_dating2$set_up_friend)
summary(clean_dating2$set_up_friend)
sd(clean_dating2$set_up_friend, na.rm = TRUE)

#First is the mean attractiveness score, by the treatment
data.summary1 <- tapply(clean_dating2$set_up_friend, clean_dating2$same_party, mean)
#Then, we need the n (to find standard error in a bit)
data.summary2 <- tapply(clean_dating2$set_up_friend, clean_dating2$same_party, length)
#Next is the standard deviation, by the treatment
data.summary3 <- tapply(clean_dating2$set_up_friend, clean_dating2$same_party, sd)

###Making this so that I can merge all the variables in a hot sec
data.summary4 <- c(5, 5)

#Now that we have our values, we will put them into a dataset.
#Note: we have to manually create the treatment columns so we can put the above values in.
data.summarySET <- data.frame("samep" = 0:1)
#Stick in the other variables
data.summarySET$mean <- data.summary1
data.summarySET$n <- data.summary2
data.summarySET$sd <- data.summary3
data.summarySET$number <- data.summary4
#Now, the magic of getting the standard error
data.summarySET$se <- data.summarySET$sd/sqrt(data.summarySET$n)

########################################################################
########################################################################
######################################################################## Mergy Mergy chicken dinner

rom <- merge(data.summary, data.summaryMESSAGE, by=c("number", "n", "sd", "se", "samep", "mean"), all=TRUE)
rom2 <- merge(rom, data.summaryDATE, by=c("number", "n", "sd", "se", "samep", "mean"), all=TRUE)
rom3 <- merge(rom2, data.summaryREL, by=c("number", "n", "sd", "se", "samep", "mean"), all=TRUE)
rom4 <- merge(rom3, data.summarySET, by=c("number", "n", "sd", "se", "samep", "mean"), all=TRUE)

#Let's create some color
rom4$color <- NA
rom4$color[rom4$samep==0] <- "darkgray"
rom4$color[rom4$samep==1] <- "darkgreen"

#For whatever reason, the line colors were getting crazy. So, here's my attempt to fix it
#(manually giving more color)
#rom4$color2 <- NA
#rom4$color2[rom4$number<=2] <- "grey"
#rom4$color2[rom4$sd=='1.0292806'] <- "maroon"
#rom4$color2[rom4$number==3] <- "maroon"
#rom4$color2[rom4$number>=4] <- "steelblue"
rom4$color3 <- c("darkgrey", "darkgrey", "darkgrey", "darkgrey", "darkgreen", "darkgreen", "darkgreen", "darkgreen", "darkgreen", 
                 "darkgreen")
##########################
########################## Let's Graph, Paw Patrol!
bb <- ggplot(data = rom4, aes(x=number, y=mean, group=samep)) +
  #xlim(0.8,5.2) +
  geom_point(color = rom4$color, size = 5, alpha =0.5) +
  geom_line(color = rom4$color3, size= 4, alpha=0.6) +
  geom_errorbar(aes(ymin=rom4$mean-(1.96*rom4$se), ymax=rom4$mean+(1.96*rom4$se)), width=0, 
                color=rom4$color, size = 2, alpha = 0.8) +
  labs(title="", x="", y = "Average Score, standardized") +
  theme_classic() +
  annotate("text", x = 1, y = -0.55, label = "Attractiveness", size = 4.75, color = "#494949") +
  annotate("text", x = 1, y = -0.57, label = "Score", size = 4.75, color = "#494949") +
  annotate("text", x = 2, y = -0.55, label = "Respond to a", size = 4.75, color = "#494949") +
  annotate("text", x = 2, y = -0.57, label = "Message", size = 4.75, color = "#494949") +
  annotate("text", x = 3, y = -0.55, label = "Go on a", size = 4.75, color = "#494949") +
  annotate("text", x = 3, y = -0.57, label = "Date", size = 4.75, color = "#494949") +
  annotate("text", x = 4, y = -0.55, label = "Enter into a", size = 4.75, color = "#494949") +
  annotate("text", x = 4, y = -0.57, label = "Relationship", size = 4.75, color = "#494949") +
  annotate("text", x = 5, y = -0.55, label = "Set Up With a", size = 4.75, color = "#494949") +
  annotate("text", x = 5, y = -0.57, label = "Friend", size = 4.75, color = "#494949") +
  scale_x_discrete() +
  annotate("text", x=2, y=0.134, label = "Profile is Same Party", size= 6, color="darkgreen") +
  annotate("text", x=4, y=-0.17, label = "Profile is Different Party", size= 6, color="darkgrey")

print(bb) // same party

